package com.itheima.health.dao;

import com.itheima.health.pojo.Member;
import com.itheima.health.pojo.Order;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;
import java.util.Set;

public interface OrderMapper extends Mapper<Order> {
    @Select("SELECT t2.name as member, t3.name as setmeal, t1.orderDate, t1.orderType FROM t_order t1 JOIN t_member t2 ON t1.member_id = t2.id JOIN t_setmeal t3 ON t1.setmeal_id = t3.id WHERE t1.id =#{id}")
    Map<String, Object> findById(Integer id);

    Integer getOrderNumber(@Param("startTime") String startTime,
                           @Param("endTime") String endTime,
                           @Param("orderStatus") String orderStatus);

    @Select("SELECT t2.`name`, count(t1.id) AS setmeal_count, count(t1.id) /( select count(id) from t_order ) as proportion FROM t_order t1 JOIN t_setmeal t2 ON t1.setmeal_id = t2.id GROUP BY t1.setmeal_id")
    List<Map<String, String>> gethotSetmeal();

    @Select("SELECT  t2.* FROM `t_order` t1,t_member  t2  WHERE DATE_FORMAT(orderDate,'%Y-%m-%d') = date_add(DATE_FORMAT(NOW(),'%Y-%m-%d'), interval 1 day)  AND t1.member_id=t2.id")
    Set<Member> findTomMember();

/*    @Select("SELECT t_member.name,t_member.phoneNumber,t_order.* FROM t_member,t_order where t_order.member_id=t_member.id AND t_order.orderStatus=\"待确认\" LIMIT 0,100")
    List<Map<String,Object>> getFindPage();*/

}
